summaryNumericDialog <- function () 
{
	require(TeachingExtras)
#	require(abind)
#	require(e1071)
	initializeDialog(title = gettext("Descriptive summary",domain="R-RcmdrPlugin.TeachingExtras"))
	xBox <- variableListBox(top, Numeric(), selectmode = "multiple", 
			title = gettext("Variables (pick one or more)",domain="R-RcmdrPlugin.TeachingExtras"))
	checkBoxes(frame = "checkBoxFrame", boxes = c("mean", "variance", "unvariance", "stdev", "sd", "cv", "skewness", "kurtosis"), 
			   initialValues = c("1", "0", "0", "1", "0", "0", "0", "0"), 
			   labels = gettext(c("Mean", "Variance", "Unbiased variance", "St.Desviation", "Unbiased St.Desviation", "Coef.Variation", "Skewness coef.", "Kurtosis coef."),domain="R-RcmdrPlugin.TeachingExtras"))
	quantilesVariable <- tclVar("0")
	quantilesFrame <- tkframe(top)
	quantilesCheckBox <- tkcheckbutton(quantilesFrame, variable = quantilesVariable)
	quantiles <- tclVar("0,.25,.5,.75,1")
	quantilesEntry <- tkentry(quantilesFrame, width = "20", textvariable = quantiles)
	groupsBox(recall = summaryNumericDialog, label = gettext("Summarize by:",domain="R-RcmdrPlugin.TeachingExtras"), 
			initialLabel = gettext("Summarize by groups",domain="R-RcmdrPlugin.TeachingExtras"))
	onOK <- function() {
		x <- getSelection(xBox)
		if (length(x) == 0) {
			errorCondition(recall = summaryNumericDialog, message = gettext("You must select at least a variable.",domain="R-RcmdrPlugin.TeachingExtras"))
			return()
		}
		closeDialog()
		quants <- paste("c(", gsub(" ", ",", tclvalue(quantiles)), ")")
		.activeDataSet <- ActiveDataSet()
		vars <- if (length(x) == 1) 
					paste("\"", x, "\"", sep = "")
				else paste("c(", paste("\"", x, "\"", collapse = ", ", sep = ""), ")", sep = "")
		vars <- paste(.activeDataSet, "[,", vars, "]", sep = "")
		stats <- paste("c(", paste(c("\"mean\"", "\"variance\"", "\"unvariance\"", "\"stdev\"", "\"sd\"", "\"cv\"", "\"skewness\"", "\"kurtosis\"", "\"quantiles\"")
				 [c(tclvalue(meanVariable), tclvalue(varianceVariable), tclvalue(unvarianceVariable), tclvalue(stdevVariable), tclvalue(sdVariable), tclvalue(cvVariable), tclvalue(skewnessVariable), tclvalue(kurtosisVariable), tclvalue(quantilesVariable)) == 1], collapse = ", "), ")", sep = "")
		if (stats == "c()") {
			errorCondition(recall = summaryNumericDialog, message = gettext("No statistics selected.",domain="R-RcmdrPlugin.TeachingExtras"))
			return()
		}
		command <- if (.groups != FALSE) {
					grps <- paste(.activeDataSet, "$", .groups, sep = "")
					paste("summaryNumeric(", vars, ", groups=", grps, ", statistics=", stats, ", quantiles=", quants, ")", sep = "")
				}
				else paste("summaryNumeric(", vars, ", statistics=", stats, ", quantiles=", quants, ")", sep = "")
		doItAndPrint(command)
		tkfocus(CommanderWindow())
	}
	OKCancelHelp(helpSubject = "summaryNumeric")
	tkgrid(getFrame(xBox), sticky = "nw")
	tkgrid(checkBoxFrame, sticky = "w")
	tkgrid(tklabel(quantilesFrame, text = gettext("Quantiles",domain="R-RcmdrPlugin.TeachingExtras")), 
			quantilesCheckBox, tklabel(quantilesFrame, text = gettext("quantiles: ",domain="R-RcmdrPlugin.TeachingExtras")), 
			quantilesEntry, sticky = "w")
	tkgrid(quantilesFrame, sticky = "w")
	tkgrid(groupsFrame, sticky = "w")
	tkgrid(buttonsFrame, sticky = "w")
	dialogSuffix(rows = 6, columns = 1)
}
